
import java.util.Date;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author VO CHI DUNG
 */
public class ListWork {

    private List listWork;
    private PlanTable parent;

    public ListWork(PlanTable p)
    {
        parent = p;
        listWork = new List("Choose type", List.IMPLICIT);
        listWork.addCommand(GlobalVariableStatic.CMD_EXIT);

//        listWork.addCommand(GlobalVariableStatic.CMD_INSERT);
//        listWork.addCommand(GlobalVariableStatic.CMD_DELETE);
//        listWork.addCommand(GlobalVariableStatic.CMD_DELETEALL);
//        listWork.addCommand(GlobalVariableStatic.CMD_EDIT);
//        listWork.addCommand(GlobalVariableStatic.CMD_CONFIGURATION);
//        listWork.addCommand(GlobalVariableStatic.CMD_ABOUT);

        listWork.addCommand(GlobalVariableStatic.CMD_MENU);

        listWork.setCommandListener(parent);

    }

    public void loadListWork(DataTask dataTask) {
        listWork.deleteAll();
        RecordTask[] arRecordTasks = dataTask.selectRecordTasks();
        if(arRecordTasks == null)
            return;
        String sString = null;
        for (int i = 0; i < arRecordTasks.length; ++i) {
            sString = arRecordTasks[i].sName + " " + new Date(arRecordTasks[i].lTime).toString();
            listWork.append(sString, null);
        }
    }

    public void HandleInput(Command c)
    {
        if(GlobalVariableStatic.CMD_EXIT == c)
        {
            parent.Exit();
        }
        else if(GlobalVariableStatic.CMD_MENU == c)
        {
            GlobalVariableStatic.SelectedWork = -1;
            parent.Switch(GlobalVariableStatic.MENU);
        }
        else if(List.SELECT_COMMAND == c)
        {
            GlobalVariableStatic.SelectedWork = listWork.getSelectedIndex();
            parent.Switch(GlobalVariableStatic.MENU);
        }

//        if(GlobalVariableStatic.CMD_INSERT == c)
//        {
//            parent.Switch(GlobalVariableStatic.INSERT);
//            //parent.Exit();
//        }
//        if(GlobalVariableStatic.CMD_DELETE == c)
//        {
//            //parent.Switch(GlobalVariableStatic.INSERT);
//            //parent.Exit();
//        }
//        if(GlobalVariableStatic.CMD_DELETEALL == c)
//        {
//            //parent.Switch(GlobalVariableStatic.INSERT);
//            //parent.Exit();
//        }
//        if(GlobalVariableStatic.CMD_EDIT == c)
//        {
//            parent.Switch(GlobalVariableStatic.EDIT);
//            //parent.Exit();
//        }
//        if(GlobalVariableStatic.CMD_CONFIGURATION == c)
//        {
//            parent.Switch(GlobalVariableStatic.CONGIGURATION);
//            //parent.Exit();
//        }
//        if(GlobalVariableStatic.CMD_ABOUT == c)
//        {
//            //parent.Exit();
//        }
    }

    public List GetForm()
    {
        return listWork;
    }
}
